var app = getApp();
Page({
  data: {
    userArray: [],
    defaultSize: 'default',
    disabled: false,
    plain: false,
    loading: false,
    grzx: app.myUlife.ulifeUrl + '/wx/grzx.jpg',
    

    nickName:'未授权',
    avatarUrl: app.myUlife.ulifeUrl + '/wx/defaultimg.jpg',

    showsqModalStatus: false,//提示弹出
  },

  onLoad: function () {
    var that = this;
    var openid = wx.getStorageSync('openid');
    var pages = getCurrentPages();
    var prevPage = pages[pages.length -2];  //上一个页面
    var stus = prevPage.data.stus;
    that.setData({
      userArray: stus
    });
    if (openid == "") {
      wx.redirectTo({
        url: '../../pages/index/index'
      })
    } 
    
  },



  buttona: function (e) {
    var index = e.target.dataset.index;
    var userArray = this.data.userArray;
  
    for (var i = 0; i < userArray.length;i++){
      if (index==i){
        wx.removeStorageSync('name');
        wx.removeStorageSync('identity');
        wx.removeStorageSync('nj');
        wx.removeStorageSync('bj');
        wx.removeStorageSync('usid');
        wx.removeStorageSync('dlzh');
        wx.removeStorageSync('sex');
        wx.removeStorageSync('user_type');
        wx.setStorageSync('name', userArray[i].name);
        wx.setStorageSync('identity', userArray[i].identity);
        wx.setStorageSync('nj', userArray[i].nj);
        wx.setStorageSync('bj', userArray[i].bj);
        wx.setStorageSync('usid', userArray[i].usid);
        wx.setStorageSync('dlzh', userArray[i].dlzh);
        wx.setStorageSync('user_type', userArray[i].user_type);
        wx.setStorageSync('sex', userArray[i].sex);
      }
    }
    
    //相当于直接登录
    wx.switchTab({
      url: '../../pages/home/home'
    })

  },





//...................授权获取用户基本信息......................
  opensqdl() {
    var nickName = this.data.nickName;
    if (nickName =='未授权'){
      this.qrsqopen("open");
    }
  },
  qrsqShow(e) {
    var currentStatu = e.currentTarget.dataset.statu;
    this.qrsqopen(currentStatu);
  },
  cancelopen() {
    this.qrsqopen("close");
  },
  qrsqopen: function (currentStatu) {
    /* 动画部分 */
    // 第1步：创建动画实例   
    var animation = wx.createAnimation({
      duration: 200, //动画时长  
      timingFunction: "linear", //线性  
      delay: 0 //0则不延迟  
    });

    // 第2步：这个动画实例赋给当前的动画实例  
    this.animation = animation;

    // 第3步：执行第一组动画  
    animation.opacity(0).rotateX(-100).step();

    // 第4步：导出动画对象赋给数据对象储存  
    this.setData({
      animationData: animation.export()
    })

    // 第5步：设置定时器到指定时候后，执行第二组动画  
    setTimeout(function () {
      // 执行第二组动画  
      animation.opacity(1).rotateX(0).step();
      // 给数据对象储存的第一组动画，更替为执行完第二组动画的动画对象  
      this.setData({
        animationData: animation
      })
      //关闭  
      if (currentStatu == "close") {
        this.setData({
          showsqModalStatus: false
        });
      }
    }.bind(this), 200)
    // 显示  
    if (currentStatu == "open") {
      this.setData({
        showsqModalStatus: true
      });
    }
  },
  onGotUserInfo(e) {
    wx.removeStorageSync('city');
    wx.removeStorageSync('province');
    wx.removeStorageSync('gender');
    wx.removeStorageSync('nickName');
    wx.removeStorageSync('avatarUrl');

    //加入缓存
    var userInfo = e.detail.userInfo;
    wx.setStorageSync('city', userInfo.city);
    wx.setStorageSync('province', userInfo.province);
    wx.setStorageSync('gender', userInfo.gender);
    wx.setStorageSync('nickName', userInfo.nickName);
    wx.setStorageSync('avatarUrl', userInfo.avatarUrl);

    this.setData({
      gender: userInfo.gender,
      avatarUrl: userInfo.avatarUrl,
      nickName:userInfo.nickName
    });
    this.qrsqopen("close");
  },

//...................授权获取用户基本信息end......................





})